<script setup>
import { defineEmits,ref } from 'vue'

const emit= defineEmits(['addTodo'])
const newThing = ref('')
const addTodo = () => {
  if (newThing.value) {
    emit('addTodo', newThing)
    newThing.value = ''
  }
}
</script> 
<template> 
    <div class="myhead">
        <h2>My ToDo List</h2>
        <div class="box">
            <input type="text" placeholder="请输入待办事项..." class="thing" v-model="newThing" @keyup.enter="addTodo">
            <button class="add" @click="addTodo">添加</button>
        </div>
    </div>
</template> 
<style scoped></style>